export function registerResize(resizeDom, resizeHandler) {
  if (!(window && window.requestAnimationFrame)) {
    return null;
  }

  let resizing = false;

  const handleResize = () => {
    if (resizing) {
      return;
    }

    resizing = true;

    window.requestAnimationFrame(() => {
      resizeHandler();

      resizing = false;
    });
  };

  if (window.ResizeObserver) {
    const observer = new window.ResizeObserver(handleResize);

    observer.observe(resizeDom);

    return observer.disconnect;
  } else if (window.addEventListener) {
    window.addEventListener("resize", handleResize);

    return () => {
      window.removeEventListener("resize", handleResize);
    };
  }

  return null;
}
